Skip to content

Feature/safo6 nrl 721 seed sandbox data#1140

Open
sandyforresternhs wants to merge 30 commits intodevelopfrom
feature/SAFO6-NRL-721-seed-sandbox-data
Open

Feature/safo6 nrl 721 seed sandbox data#1140
sandyforresternhs wants to merge 30 commits intodevelopfrom
feature/SAFO6-NRL-721-seed-sandbox-data

Conversation

@sandyforresternhs
Copy link
Contributor

@sandyforresternhs sandyforresternhs commented Feb 10, 2026

  • Deletes all items in a DynamoDB table and reseeds the table with X (default = 2) pointers of each type for X (default is 2) custodians
  • The scripts have been implemented to allow for execution either locally or via the lambda
  • When running locally, the delete_all_table_items.py and seed_sandbox_table.py scripts can be run independently or via the orchestrator script reset_sandbox_table.py
  • The lambda handles the orchestration of the delete and seed scripts (index.py), so the reset_sandbox_table.py script is not required for the lambda
  • The lambda is deployed account-wide to dev and/or test (since we wouldn't want to reseed prod tables) and only when a table in the account has been specified for reseeding
  • Logs showing the lambda working successfully can be seen here
  • Because it's account-wide we have needed to make the lamda layers available in the a/c wide infrastructure

@github-actions
Copy link

💥 Something went wrong while deploying the pull request environment.
Check Output Logs

@github-actions
Copy link

🚀 PR environment successfully deployed.
Commit Hash: 1c7c0abbd7cb49c7aa4d6c482f6dcd6a538d0daa
URL: https://nrl721-01ba47.api.record-locator.dev.national.nhs.uk/

@github-actions
Copy link

🚀 PR environment successfully deployed.
Commit Hash: 3b56521bd8cc2e70e7282738b296bbdae3c011c1
URL: https://nrl721-01ba47.api.record-locator.dev.national.nhs.uk/

@github-actions
Copy link

🚀 PR environment successfully deployed.
Commit Hash: 5aebcd6b07f468d3817ba67175ee537d70cc1cfe
URL: https://nrl721-01ba47.api.record-locator.dev.national.nhs.uk/

@github-actions
Copy link

🚀 PR environment successfully deployed.
Commit Hash: 012fa4fbf6a2a785d25f1c244be7879e01933d74
URL: https://nrl721-01ba47.api.record-locator.dev.national.nhs.uk/

Copy link
Contributor

@mattdean3-nhs mattdean3-nhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is EPIC 💪 nice work!

A few passing comments that I'd be happy to ignore.

Only one that we might need to address is the "*" wildcard used on the KMS key access for the new lambda - do we have an option to restrict that?

delete_all_table_items("nonexistent-table")

mock_exit.assert_called_once_with(1)
mock_print.assert_called_with("Error: Table 'nonexistent-table' does not exist")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oooof - nice! 💪 am liking this mocking of exit and print.... definitely going to borrow that approach 😁

import boto3
from botocore.exceptions import ClientError

# Needed for when the script is run in Lambda where modules are in scripts subdirectory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these path/import issues could be fixed by adjusting the lambda runtime environment a little - but not a biggie for now, happy to leave as is and come back to fix later if ever needed. 👍


locals {
# take these out once development & testing is complete
seed_table_names = ["nhsd-nrlf--sandy-dev-pointers-table", "nhsd-nrlf--sandycopy-dev-pointers-table"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probs remove sandycopy from list? or planning to do that after some testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left those two in for the time being just so that we could see it works with multiple tables, and we can see in the logs they're both getting reseeded. I think the testers will probably want to add and remove tables, but I'm assuming that once we're all happy to merge we can remove the tables listed for dev completely, just leaving the int-sandbox table for test

description = "Rule to clear and reseed sandbox data"
# Set this to weekly once development and testing is complete
# schedule_expression = "cron(0 2 ? * SUN *)" # 2am UTC, every Sunday
schedule_expression = "cron(0/15 9-17 ? * MON-FRI *)" # Every 15 minutes, 9am-5pm UTC, Monday-Friday
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth making this schedule a module var? that way we could have different schedules for dev and test if we want. Not sure if it's worth it though, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call, yep will do that 👍

"kms:Decrypt",
"kms:DescribeKey"
]
Resource = "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an option to restrict this to a specific key? rather than all keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, let's do that 👍

# Only deploys if tables are specified

locals {
seed_table_names = ["nhsd-nrlf--int-sandboxcopy-pointers-table"] # Change to int-sandbox-pointers-table when ready
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to correct table name before merge (or add the correct one and keep both for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I was thinking just before merge assuming we're happy for int to get cleared - not sure if we want to give customers the heads up first?

@sonarqubecloud
Copy link

@github-actions
Copy link

🚀 PR environment successfully deployed.
Commit Hash: 1938493df29f9fd8513c7464c47733e97bbf4fe1
URL: https://nrl721-01ba47.api.record-locator.dev.national.nhs.uk/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments